package com.example.work4.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.view.View
import androidx.databinding.ViewDataBinding
import com.example.work4.BR
import com.example.work4.R
import com.example.work4.adapter.viewHolder.CommentViewHolder
import com.example.work4.common.FIN
import com.example.work4.po.Comment

class CommentsAdapter(var context: Context,var momentId:Int):CaseAdapter<Comment>(), View.OnClickListener {

    override fun onBindViewHolder(holder: CommentViewHolder, position: Int) {
        val binding : ViewDataBinding = holder.dataBinding
        if(data[position].replyUserId == 0L){
            holder.huifu.visibility = View.GONE
        }
        holder.handler = mHandler
        holder.momentId = momentId;
        holder.comment = data[position]
        binding.setVariable(BR.comment, data[position])
    }

    override fun getItemViewType(position: Int): Int {
        return R.layout.item_comment
    }

    public val mHandler: Handler = object : Handler(Looper.getMainLooper()) {
        @SuppressLint("NotifyDataSetChanged", "CutPasteId")
        override fun handleMessage(msg: Message) {
            super.handleMessage(msg)
            when (msg.what) {
                FIN.UPDATECOMMENTLIST->{
                    data = msg.obj as ArrayList<Comment>
                    update()
                }
            }
        }
    };

    @SuppressLint("NotifyDataSetChanged")
    fun update(){
        this.notifyDataSetChanged()
    }



    override fun onClick(v: View?) {
    }
}